package com.hrhr74.penguinstream.service;

import com.hrhr74.penguinstream.domain.login.UserLogin;
import com.hrhr74.penguinstream.utils.Result;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@Data
public class LoginContext {

    private final Map<String ,LoginStrategy> map;

    public LoginContext(Map<String, LoginStrategy> map) {
        this.map = map;
    }

    public Result userLogin(UserLogin userLogin) {
        if(userLogin==null){
            return Result.error("不支持该登录方式！");
        }
        String loginType = userLogin.getLoginType();
        LoginStrategy loginStrategy = map.get(loginType);
        if(loginStrategy==null){
            return Result.error("不支持该登录方式！");
        }
        return loginStrategy.login(userLogin);
    }
}
